package main;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

class ThreadPool implements ServerConcurrencyModel {

	private ExecutorService _executor;

	public ThreadPool(int iNumberOfThreads) {
		_executor = Executors.newFixedThreadPool(iNumberOfThreads);
	}

	public void apply(Runnable connectionHandler) {
		_executor.execute(connectionHandler);
	}

	@Override
	public void stop() {
		System.out.println("shutting down main thread pool");
		_executor.shutdownNow();
		while (!_executor.isTerminated()) {
			System.out.println("ggggggg");
			_executor.shutdownNow();
		}
	}
}